<template>
  <div id="formcenter">
    <div class="tradetop">报单中心信息</div>
     <div class="tradesell" v-if="baodan==='1'">
        <div class="message">
            <ul>
                <li>名称：&emsp;&emsp;&emsp;<input type="text" v-model="name" placeholder="我是用户名" readonly="readonly"></li>
                <li>地址：&emsp;&emsp;&emsp;<input type="text" v-model="address" placeholder="地址显示" readonly="readonly"></li>
                <li>联系方式：&emsp;<input type="text" v-model="contact" placeholder="我的联系方式" readonly="readonly"></li>
            </ul>
        </div>
    </div>

    <div class="tradesell"  v-if="baodan==='2'">
        <div class="message">
            <ul>
                <li>名称：&emsp;&emsp;&emsp;<input type="text" v-model="name" placeholder="我是用户名"></li>
                <li>地址：&emsp;&emsp;&emsp;<input type="text" v-model="address" placeholder="地址显示"></li>
                <li>联系方式：&emsp;<input type="text" v-model="contact" placeholder="我的联系方式"></li>
            </ul>
        </div>
        <div class="btn">
            <button @click="verification">确定修改</button>
            <!-- <button>取消</button> -->
        </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "formcenter",
  data() {
    return {
      name: "",
      address: "",
      contact: "",
      baodan: '' //获取报单状态
    };
  },
  created () {
    var baodan = sessionStorage.getItem('type');
    this.baodan = baodan;
    console.log(this.baodan);

  },
  mounted() {
    this.loadmes();
  },
  methods: {
    loadmes() {
      this.axios
        .post("User/center_info")
        .then(({ data }) => {
          console.log(data);
          this.name = data.info.center_name;
          this.address = data.info.center_address;
          this.contact = data.info.center_phone;
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    verification() {
      var isPhone = /^[a-zA-Z0-9]{6,11}$/;
      if (!this.name) {
        this.$message({ message: "用户名不能为空", type: "error" });
      } else if (!this.address) {
        this.$message({ message: "地址不能为空", type: "error" });
      } else if (!isPhone.test(this.contact)) {
        this.$message({ message: "联系方式格式不合法", type: "error" });
      } else
        this.axios
          .post("User/center_info_cl", {
            address: this.address,
            name: this.name,
            phone: this.contact
          })
          .then(({ data }) => {
            console.log(data);
            if (data.status === "1") {
              (this.address = ""),
                (this.contact = ""),
                this.$message({ message: "修改成功", type: "success" });
            } else if (data.status === "2") {
              this.$message({ message: "修改失败", type: "error" });
            }
          })
          .catch(function(error) {
            console.log(error);
          });
    }
  }
};
</script>

<style lang="scss">
#formcenter {
  .tradetop {
    width: 100%;
    height: 55px;
    line-height: 65px;
    font-size: 13px;
    font-family: MicrosoftYaHei-Bold;
    color: rgba(0, 0, 0, 1);
    font-weight: 700;
    padding-left: 25px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(153, 153, 153, 1);
  }
  .tradesell {
    .message {
      margin-left: 40px;
      margin-top: 10px;
      li {
        line-height: 50px;
        font-size: 12px;
        font-family: MicrosoftYaHei;
        color: rgba(102, 102, 102, 1);
      }
      input {
        width: 209px;
        height: 33px;
        padding-left: 5px;
        border-radius: 2px;
        border: 1px solid rgba(151, 151, 151, 1);
      }
      li:nth-of-type(1) {
        span {
          font-weight: 700;
        }
      }
      li:nth-of-type(4) {
        span {
          color: rgba(224, 3, 0, 1);
        }
      }
      li:nth-of-type(4),
      li:nth-of-type(5) {
        span {
          font-weight: 700;
        }
      }
    }
    .btn {
      margin-top: 50px;
      margin-left: 40px;
      button {
        width: 82px;
        height: 33px;
        background: rgba(224, 3, 0, 1);
        font-size: 12px;
        font-family: MicrosoftYaHei;
        color: rgba(255, 255, 255, 1);
        border-radius: 2px;
      }
      button:nth-of-type(2) {
        margin-left: 25px;
        background: rgba(225, 225, 225, 1);
        color: rgba(0, 0, 0, 1);
      }
    }
  }
}
</style>
